package lpd2i.projetAndroid;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Main extends Activity {
	//gestionaire de contenu
	private LinearLayout layout;
	
	private static Location loc;
	
	private static TextView latitude;
	private static TextView longitude;
	private static TextView altitude;

	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		//creation d'un gestionaire de contenu
		layout = new LinearLayout(this);
		setContentView(layout);

		//mode d'alignement des elements
		layout.setOrientation(LinearLayout.VERTICAL);
		layout.setGravity(Gravity.TOP|Gravity.CENTER);

		//ajout des composants graphiques
		latitude = new TextView(this);
		latitude.setText("latitude");
		latitude.setId(1);
		layout.addView(latitude);

		longitude = new TextView(this);
		longitude.setText("longitude");
		longitude.setId(2);
		layout.addView(longitude);

		altitude = new TextView(this);
		altitude.setText("altitude");
		altitude.setId(3);
		layout.addView(altitude);

		//---utilisation  de la class LocationManager pour le gps--- 
		LocationManager objgps = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
		
		try {
		    loc = objgps.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		} catch (SecurityException e) {
			latitude.setText("scurity exeption");
		} catch (IllegalArgumentException e){
			longitude.setText("probleme avec le provider");
			
		}
		
        //*************ecouteur ou listener*********************
        EcouteurPosition listener = new EcouteurPosition(); 
         
        objgps.requestLocationUpdates( 
            LocationManager.GPS_PROVIDER, 
            0, 
            0, 
            listener);
        	
	}
    public static void setCoordonnees() {
		latitude.setText("latitude  : "+loc.getLatitude());
		longitude.setText("longitude : "+loc.getLongitude());
		altitude.setText("altitude  : "+loc.getAltitude());	
    }
	public static void setCoordonnees(double lat, double lon, double alt) {
		latitude.setText("latitude  : "+lat);
		longitude.setText("longitude : "+lon);
		altitude.setText("altitude  : "+alt);	
	}
}